package com.share.rules.controller;

import com.share.common.core.domain.R;
import com.share.common.core.web.controller.BaseController;
import com.share.rule.api.domain.FeeRule;
import com.share.rule.api.domain.FeeRuleRequestForm;
import com.share.rule.api.domain.FeeRuleResponseVo;
import com.share.rules.service.IFeeRuleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 费用规则控制器
 *
 * @author YC
 */
@Tag(name = "费用规则接口管理")
@RestController
@RequestMapping("/feeRule")
public class FeeRuleController extends BaseController {

    @Autowired
    private IFeeRuleService feeRuleService;

    /**
     * 远程被调用 - 计算订单费用
     *
     * @param feeRuleRequestForm 规则请求表单
     * @return 封装的规则计算响应
     */
    @PostMapping("/calculateOrderFee")
    public R<FeeRuleResponseVo> calculateOrderFee(@RequestBody FeeRuleRequestForm feeRuleRequestForm) {
        FeeRuleResponseVo feeRuleResponseVo = feeRuleService.calculateOrderFee(feeRuleRequestForm);
        return R.ok(feeRuleResponseVo);
    }

    /**
     * 远程被调用 - 根据规则ID集合批量获取费用规则信息
     *
     * @param feeRuleIds 规则ID集合
     * @return 规则信息集合
     */
    @Operation(summary = "根据规则ID集合批量获取费用规则信息")
    @PostMapping(value = "/getFeeRuleList")
    public R<List<FeeRule>> getFeeRuleList(@RequestBody List<Long> feeRuleIds) {
        return R.ok(feeRuleService.listByIds(feeRuleIds));
    }

    /**
     * 远程被调用 - 根据规则ID获取费用规则详细信息
     *
     * @param id 规则ID
     * @return 规则详细信息
     */
    @Operation(summary = "根据规则ID获取费用规则详细信息")
    @GetMapping(value = "/getFeeRule/{id}")
    public R<FeeRule> detailFeeRule(@PathVariable("id") Long id) {
        return R.ok(feeRuleService.getById(id));
    }

}

